import { shopAxios } from "@/utils/http";


// xxxxxxxxxxxxxxxxxxxxxxxxxxx 商品类 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

// 获取商品
export const getGoodsList = (goodsObj) => {
  return shopAxios.get('/goods/list', {
    params: goodsObj,
  });
};

// {
//   current: 1,
//   pagesize: 12,
//   search: '',
//   filter: '',
//   saleType: 10,
//   sortType: 'id',
//   sortMethod: 'ASC',
//   category: '',
// }

// 获取商品详细信息
export const getGoodsItem = (id) => {
  return shopAxios.get('/goods/item', {
    params: { id },
  });
};

// 获取分类列表
export const getCategory = () => {
  return shopAxios.get('/goods/category', {});
};

// xxxxxxxxxxxxxxxxxxxxxxxxxxx 用户类 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// 登录
export const doLogin = (user, pass) => {
  return shopAxios.post('/users/login', {

      username: user,
      password: pass,

  });
};

// 登出
export const doLogout = (id) => {
  return shopAxios.get('/users/logout', {
    params: { id },
  });
};

// 注册
export const doRegister = (registerObj) => {
  console.log(registerObj);
  return shopAxios.post('/users/register', {
    username: registerObj.user || '',
    password: registerObj.pass || '',
    rpassword: registerObj.checkPass || '',
    nickname: registerObj.nick || '',
    // username: 'qiyana',
    // password: '123456',
    // rpassword: '123456',
    // nickname: '123'
  });
};

// 获取用户信息
export const getUserInfo = (id) => {
  return shopAxios.get('/users/info', {
    params: { id },
  });
};

// 修改个人资料
export const doUpdate = (updateObj) => {
  return shopAxios.post('/users/update', {
    id: updateObj.id,
    age: updateObj.age || '',
    gender: updateObj.gender || '',
    nickname: updateObj.nickName || '',
  });
};

// 修改密码
export const doRpwd = (rpwdObj) => {
  return shopAxios.post('/users/rpwd', {
    id: rpwdObj.id || '',
    oldPassword: rpwdObj.oldPass || '',
    newPassword: rpwdObj.newPass || '',
    rNewPassword: rpwdObj.checkPass || '',
  });
};

// xxxxxxxxxxxxxxxxxxxxxxxxxxx 用户类 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// 获取购物车列表
export const getCartList = (id) => {
  return shopAxios.get('/cart/list', {
    params: { id },
  });
};

// 加入购物车
export const addCart = (id, goodsId) => {
  return shopAxios.post('/cart/add', {
    id,
    goodsId,
  })
};

// 删除购物车的一条商品
export const removeItemCart = (id, goodsId) => {
  return shopAxios.get('/cart/remove', {
    params: {
      id,
      goodsId,
    },
  });
};

// 删除所有已选中的商品
export const removeSelectedCart = (id) => {
  return shopAxios.get('/cart/remove/select', {
    params: { id },
  });
};

// 清空购物车
export const clearCart = (id) => {
  return shopAxios.get('/cart/clear', {
    params: { id },
  });
};

// 修改一条商品的选中状态
export const changeSelectCart = (id, goodsId) => {
  return shopAxios.post('/cart/select', {
    id,
    goodsId,
  });
};

// 修改全部商品的选中状态
export const changeSelectAllCart = (id, type) => {
  console.log(type)
  return shopAxios.post('/cart/select/all', {
    id,
    type,
  });
};

// 修改购买数量
export const changeNumberCart = (id, goodsId, number) => {
  return shopAxios.post('/cart/number', {
    id,
    goodsId,
    number,
  });
};

// 支付
export const doPay = (id) => {
  return shopAxios.post('/cart/pay', {
    id
  });
};